﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;

namespace YouHP.Pages
{
    public class Disease : BasePage
    {
       
        protected override void ShowPage()
        {
            base.ShowPage();
            if(ErrorCount > 0) return;
            
            HandleCommon();
            if(ErrorCount > 0) return;
            
            if(IsPost) HandlePost();
            else HandleGet();
        }

        // 如果用户已经登录，记录当前用户的患病信息
        protected PatientRecordInfo prData;

        protected DiseaseInfo DiseaseData;
        protected List<DiseaseSymptomInfo> SymptomDataList;
        protected List<DiseaseTreatmentInfo> TreatmentDataList;
        protected List<UserInfo> PatientDataListRelate;
        protected List<TopicInfo> TopicDataListHottest;
        protected List<TopicInfo> TopicDataListLatest;
        
        protected void HandleCommon()
        {

        }
        
        protected void HandlePost()
        {
            
        }

        protected void HandleGet()
        {
            int did = RequestTools.GetQueryInt("id", 0);
            if (did == 0)
            {
                this.AddErrLine("找不到疾病信息");
                return;
            }

            DiseaseData = DiseaseBLL.Instance.GetDiseaseInfo(did);
            if (DiseaseData.Id <= 0)
            {
                this.AddErrLine("找不到疾病信息");
                return;
            }

            this.AddLocation("疾病列表", "/DiseaseList.aspx");
            this.AddLocation(DiseaseData.Name, "/Disease.aspx?id=" + DiseaseData.Id);

            SymptomDataList = DiseaseBLL.Instance.GetDiseaseSymptomList(did);
            TreatmentDataList = DiseaseBLL.Instance.GetDiseaseTreatmentList(did);

            int n = 8;

            if (UserData.Id > 0)
            {
                PatientDataListRelate = PatientBLL.Instance.GetHottestPatientByDisease(did, n);
                TopicDataListHottest = TopicBLL.Instance.GetHottestTopicByDiseaseId(did, 10);
                TopicDataListLatest = TopicBLL.Instance.GetLastestTopic(10, did);
            }
            else
            {
                PatientDataListRelate = PatientBLL.Instance.GetHottestPatientByDisease(did, 2);
                TopicDataListHottest = TopicBLL.Instance.GetHottestTopicByDiseaseId(did, 3);
                TopicDataListLatest = TopicBLL.Instance.GetLastestTopic(3, did);
            }


            // 用户已经登录
            if (UserData.Id > 0)
            {
                prData = PatientBLL.Instance.GetPatientRecordInfo(UserData.Id);
            }

            this.SetTitle(DiseaseData.Name);
        }  
    }
}